package com.cn.web.app.order.controller;

import com.cn.annoation.Logs;
import com.cn.msg.ResultMsg;
import com.cn.page.PageVo;
import com.cn.user.UserDO;
import com.cn.util.AuthUserContext;
import com.cn.util.BaseController;
import com.cn.web.app.order.entity.OrderInfoEntity;
import com.cn.web.app.order.service.OrderInfoService;
import com.cn.web.app.order.vo.OrderInfoListVO;
import com.cn.web.app.order.vo.OrderInfoSearch;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description: OrderInfoController <br>
 * date: 24.7.12 11:57 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@RestController
@RequestMapping(value = "admin/order/info")
@Api(tags = "订单中心")
@Slf4j
public class OrderInfoController extends BaseController {

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation(value = "列表")
    @PostMapping(value = "page")
    public ResultMsg<PageInfo<OrderInfoListVO>> page(
            @RequestBody PageVo<OrderInfoSearch> pageVo
    ) {
        OrderInfoSearch search = pageVo.getParam();
        UserDO token = AuthUserContext.get();
        if (token.getSuperFlag().equalsIgnoreCase("1")) {
            search.setUserId(token.getId().toString())
                    .setType(1);
        }
        return ResultMsg.builder(this.orderInfoService.page(pageVo));
    }

    @Logs(value = "编辑", desc = "订单中心")
    @ApiOperation(value = "编辑")
    @PostMapping(value = "edit")
    public ResultMsg edit(
            @RequestBody OrderInfoEntity info
    ) {
        UserDO token = AuthUserContext.get();
        this.orderInfoService.edit(info, token);
        return ResultMsg.builder();
    }

    @Logs(value = "删除", desc = "订单中心")
    @ApiOperation(value = "删除")
    @GetMapping(value = "del")
    public ResultMsg del(
            @ApiParam(name = "id") @RequestParam String id
    ) {
        this.orderInfoService.del(id);
        return ResultMsg.builder();
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "find")
    public ResultMsg<OrderInfoEntity> find(
            @ApiParam(name = "id") @RequestParam String id
    ) {
        return ResultMsg.builder(this.orderInfoService.find(id));
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "findVO")
    public ResultMsg<OrderInfoListVO> findVO(
            @ApiParam(name = "id") @RequestParam String id
    ) {
        return ResultMsg.builder(this.orderInfoService.findVO(id));
    }
}
